<?php

namespace App\Controller;

use App\Entity\FileObject;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;

/**
 * Class UploadFilesController 文件上传
 * @package App\Controller
 */
class UploadFilesController extends AbstractController
{

    public function __invoke(Request $request)
    {
        if (!$request->files->has('file')) {
            throw new BadRequestHttpException('文件必需上传');
        }
        $filesObject = new FileObject();
        $filesObject->setFile($request->files->get('file'));
        return $filesObject;
    }
}
